﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ThresholdAssistant.Autofac;
using ThresholdAssistant.WebAPI.Models;

namespace ThresholdAssistant.WebAPI.Repository
{
    /// <summary>
    /// 预警读取表仓储
    /// </summary>
    public class RedRepository : BaseRepository, IBaseAutofac
    {
        /// <summary>
        /// 新增
        /// </summary>
        public async Task<bool> AddAsync(Red model)
        {
            string insertSql = @"insert into `t_red`
(`group_id`,`member_id`,`last_click_time`)
values
(@GroupId,@MemberId,@LastClickTime)";
            return await mydb.ExecuteAsync(insertSql, model);
        }

        /// <summary>
        /// 查询
        /// </summary>
        public async Task<Red> GetInfoAsync(long id)
        {
            string querySql = @"select
 `id`, `group_id`, `member_id`, `last_click_time`
 from `t_red`
 where id = @Id;";
            return await mydb.GetFirstOrDefaultAsync<Red>(querySql, new { Id = id });
        }

        /// <summary>
        /// 修改
        /// </summary>
        public async Task<bool> UpdateAsync(Red model)
        {
            string updateSql = @"update
`t_red`
set  `group_id`=@GroupId, `member_id`=@MemberId, `last_click_time`=@LastClickTime
 where `id` = @Id";
            return await mydb.ExecuteAsync(updateSql, model);
        }
    }
}
